package model;

import java.io.Serializable;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ReflectionToStringBuilder;


public class BaseModel implements Serializable {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = -9056854263100512667L;
	
	private Long id;

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}
	
	public boolean equals(Object obj){
		if(this==obj){
			return true;
		}
		if(!(obj instanceof BaseModel)){
			return false;
		}
		
		BaseModel target=(BaseModel)obj;
		if(this.getId()!=null&&this.getId()>0){
			return this.getId().equals(target.getId());
		}
		
		if(target.getId()!=null&&target.getId()>0){
			return false;
		}
		
		return EqualsBuilder.reflectionEquals(this,obj);
	}
	
	public int hashCode(){
		if(this.getId()!=null&&this.getId()>0){
			return this.getId().hashCode();
		}
		return HashCodeBuilder.reflectionHashCode(this);
	}
	
	public String toString(){
		return ReflectionToStringBuilder.toString(this);
	}
}
